package it.cst.entity.dao;

import it.cst.entity.Player;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class PlayerDAOImpl implements PlayerDAO{
	@Autowired
	private SessionFactory sessionFactory;
	
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	@Override
	public void addPlayer(Player player) {
		sessionFactory.getCurrentSession().save(player);
		
	}

	
	@SuppressWarnings("unchecked")
	public List<Player> listPlayer() {
		return sessionFactory.getCurrentSession().createQuery("from Player ORDER BY id").list();
	}

	@Override
	public void removePlayer(Player player) {
		sessionFactory.getCurrentSession().delete(player);
	}

	@Override
	public Player getPlayer(Integer id) {
		// TODO Auto-generated method stub
		return null;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Player> listGroupPlayer(Integer idGroup) {
		Query q = sessionFactory.getCurrentSession().createQuery("from Player WHERE idgroup = ?");
		q.setInteger(0, idGroup);
		return q.list();
		
	}

}
